package com.example.springprinciple;


import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.web.context.annotation.ApplicationScope;
import org.springframework.web.context.annotation.RequestScope;
import org.springframework.web.context.annotation.SessionScope;

@Configuration
public class CatBeanConfig {
    @Bean
    public Cat cat() {
        Cat cat = new Cat();
        cat.setName("花花");
        return cat;
    }

    @Bean
    @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON) //单例作用域
    public Cat singleCat() {
        Cat cat = new Cat();
        return cat;
    }

    @Bean
    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)  //多例作用域
    public Cat prototypeCat() {
        Cat cat = new Cat();
        return cat;
    }

    @Bean
    @RequestScope  //请求作用域
    public Cat requestCat() {
        Cat cat = new Cat();
        return cat;
    }

    @Bean
    @SessionScope  //会话作用域
    public Cat sessionCat() {
        Cat cat = new Cat();
        return cat;
    }

    @Bean
    @ApplicationScope  //全局作用域
    public Cat applicationCat() {
        Cat cat = new Cat();
        return cat;
    }
}
